package com.lexed.carmanager.controllor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.lexed.carmanager.database.pojo.bean.UserRolm;

import net.minidev.json.JSONObject;

// 检测登录状态
public class ScendServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession httpSession  =request.getSession();
		// 获取session属性
		// 如果登录成功UserRolm
		UserRolm userRolm = (UserRolm)httpSession.getAttribute("userrolm");
		// 如果是重置密码userid
		Integer userid =  (Integer)httpSession.getAttribute("userid");
		
		System.out.println("UserRolm:"+userRolm);
		
		JSONObject json = new JSONObject();
		if(userRolm != null){
			json.put("username", userRolm.getUsername());
			json.put("msg", userRolm.getMsg());
			json.put("rolm", userRolm.getRolm());
			json.put("status", userRolm.getStatus()); // 1
		}else if(userRolm == null){ // 没有用户权限信息  没有登录成功
			json.put("status", 2);
		}
		if(userid != null && userid > 0 ){ // 如果需要重置密码 userid 大于 0
			System.out.println("userid:"+userid);
			json.put("userid", userid);
		}
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().print(json.toJSONString());
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
